package com.yao.yaoojbackendjudgeservice.judge.codesandbox;

import com.yao.yaoojbackendmodel.model.codesandbox.ExecuteCodeRequest;
import com.yao.yaoojbackendmodel.model.codesandbox.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 对代码沙箱进行代理、增强
 */

@Slf4j
//@AllArgsConstructor Lombok 会为类中的每个字段生成一个参数化的构造方法。
//这个构造方法会包含类中定义的所有字段作为参数。和下面这段代码等价
// public CodeSandboxProxy(CodeSandbox codeSandbox) {
//        this.codeSandbox = codeSandbox;
//    }
public class CodeSandboxProxy implements CodeSandbox{

    private final CodeSandbox codeSandbox;

    public CodeSandboxProxy(CodeSandbox codeSandbox) {
        this.codeSandbox = codeSandbox;
    }

    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        log.info("代码沙箱请求信息："+executeCodeRequest.toString());
        ExecuteCodeResponse executeCodeResponse = codeSandbox.executeCode(executeCodeRequest);
        log.info("代码沙箱响应信息："+executeCodeResponse.toString());
        return executeCodeResponse;
    }
}
